package models

import (
	"gorm.io/gorm"
	"server/config"
	"time"
)

type User struct {
	Id         uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	Mobile     string         `gorm:"column:mobile;type:varchar(255);not null;" json:"mobile"`
	Password   string         `gorm:"column:password;type:varchar(255);not null;" json:"password"`
	Username   string         `gorm:"column:username;type:varchar(255);not null;" json:"username"`
	Nickname   string         `gorm:"column:nickname;type:varchar(255);not null;" json:"nickname"`
	HeadImg    string         `gorm:"column:head_img;type:varchar(255);comment:头像;not null;" json:"head_img"`         // 头像
	Sex        uint           `gorm:"column:sex;type:int UNSIGNED;comment:性别：1：男 2：女;not null;default:0;" json:"sex"` // 性别：1：男 2：女
	Birthday   string         `gorm:"column:birthday;type:varchar(255);not null;" json:"birthday"`
	Email      string         `gorm:"column:email;type:varchar(255);not null;" json:"email"`
	UserStatus string         `gorm:"column:user_status;type:varchar(255);comment:用户状态;not null;" json:"user_status"` // 用户状态
	Address    string         `gorm:"column:address;type:varchar(255);not null;" json:"address"`
	CreatedAt  time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt  time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (u *User) TableName() string {
	return "user"
}
func (u *User) CreateUser() error {
	return config.DB.Create(&u).Error
}
